package com.hltx.controller.app.bonus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hltx.controller.base.BaseController;
import com.hltx.pojo.common.Page;
import com.hltx.pojo.user.UserAccount;
import com.hltx.service.user.BonusManager;
import com.hltx.service.user.UserManager;
import com.hltx.util.MessagesCode;
import com.hltx.util.ResultInfo;

/**
 * APP奖金controller
 * 
 * @author
 *
 */
@Controller
@RequestMapping(value = "/app/")
public class AppBonusController extends BaseController {

	@Resource(name = "bonusService")
	private BonusManager bonusService;
	
	@Resource(name = "userService")
	private UserManager userService;

	/**
	 * 奖金数据 明细
	 */

	@RequestMapping(value = "/getBonus", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> getBonus(Page p, HttpServletRequest request, HttpSession session) {
		this.logBefore(logger, "奖励明细");
		HashMap<String, Object> map = new HashMap<String, Object>();
		String userId = request.getParameter("id");
		int start = (p.getPage()-1) * p.getShowNumber();
		p.getParams().put("id", userId);
		p.setStart(start);
		p.getParams().put("showNumber", p.getShowNumber());
		try {
			List<Map<String, Object>> bonusMap = bonusService.getBonus(p);
			UserAccount ua = userService.getAccount(userId);
			if (bonusMap.size() > 0) {
				map.put("result", this.initResult(ResultInfo.SUCCESS, MessagesCode.SUCCESS, "查询成功"));
				map.put("bonusMap", bonusMap);
				map.put("account", ua);
			} else {
				map.put("account", ua);
				map.put("result", this.initResult(ResultInfo.SUCCESS, MessagesCode.PRICE_ERROR, "未产生奖金"));
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.logError(logger, e.getMessage());
			map.put("result", this.initResult(ResultInfo.ERROR, "exception", "系统异常"));
		}
		this.logAfter(logger);
		return map;
	}
}
